First, we load required packages

library(tidyverse)
library(ggbump)
library(ggplot2)
library(cowplot)
library(magick)
library(patchwork)
library(htmltools)
library(knitr)
library(codehover)

Next, we load in data and format it for plotting

office_ratings <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-03-17/office_ratings.csv')

office_season <- office_ratings %>%
  group_by(season) %>%
  summarise(avg_rating = mean(imdb_rating, na.rm = T))

See the ggplot below. Hover over the code to see the graph being built step by step.

This is a plot looking at how IMDB ratings of The Office vary by season.

ggplot(office_season, aes(x = season, y = avg_rating)) +
geom_point(size = 4, colour = 'blue') +
geom_bump(colour = 'blue') +
theme_classic() +
scale_x_continuous(breaks = seq(0, 9, by = 1)) +
annotate('text', x = 4, y = 8.7, label = 'Season 4 was the highest rated') +
annotate('text', x = 7.5, y = 7.55, label = 'Season 8 was the lowest rated') +
ylim(7.5,8.8) +
labs(title='The Office: IMDB Ratings by Season', x ='Season', y = 'Rating')

More Advanced ggplot

Formatting data for second visualization.

library(tidyverse)
library(ggbump)
library(ggplot2)
library(cowplot)
library(magick)
library(patchwork)

office_ratings <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-03-17/office_ratings.csv')

office_season_ep <- office_ratings %>%
  group_by(season, episode) %>%
  summarise(avg_rating = mean(imdb_rating, na.rm = T))
ggplot(office_season, aes(x = season, y = avg_rating)) +
geom_point(size = .25, show.legend = FALSE) +
geom_bump(size = .25, show.legend = FALSE) +
facet_grid(~as.factor(season),scales = 'free_x') +
scale_color_manual(values = c('#332288', '#88CCEE', '#44AA99',
'#117733', '#999933', '#DDCC77',
'#CC6677', '#882255', '#AA4499')) +
geom_area(size = 1, alpha = 0.1, show.legend = FALSE, color = NA) +
scale_fill_manual(values = c('#332288', '#88CCEE', '#44AA99',
'#117733', '#999933', '#DDCC77',
'#CC6677', '#882255', '#AA4499')) +
scale_y_continuous(limits = c(0, 10)) +
theme(panel.background = element_rect(fill = '#232229', colour = '#232229')) +
theme(plot.background = element_rect(fill = '#232229', colour = '#232229')) +
theme(strip.background = element_rect(fill = '#232229', colour = '#232229')) +
theme(panel.grid.minor = element_line(colour = '#e5e5e5',
size = .10, linetype = 'dotted')) +
theme(panel.grid.major = element_line(colour = '#e5e5e5',
size = .10, linetype = 'dotted')) +
theme(axis.title.x = element_text(size = 15, colour='#e5e5e5'))) +
theme(axis.title.y = element_blank()) +
theme(axis.text.x = element_blank()) +
theme(axis.text.y = element_text(size = 12, colour='#e5e5e5')) +
theme(strip.text.x = element_text(face = 'italic', size = 15, colour='#e5e5e5')) +
theme(axis.ticks = element_blank()) +
labs(title = 'The Office: Episode ratings by season Season', x = 'Episode', y = 'IMDB Rating') +
plot_annotation(caption = '#TidyTuesday | Data: The Office | Graphic: ADPerez') +
theme(plot.title = element_text(size=20, face='bold', hjust = 0,color = '#e5e5e5'))